from keras.layers.core import Activation, Dense,activations
from keras.models import Sequential
from keras.utils.vis_utils import plot_model
from keras.layers import Flatten
from keras.layers.core import Dense
from keras.datasets import mnist
import keras 
import tensorflow

num_classes = 10
batch_size = 32
epochs = 10 
img_row, img_col = 28, 28
(x_train,y_train),(x_test,y_test) = mnist.load_data()
y_train = tensorflow.keras.utils.to_categorical(y_train, num_classes)
y_test = tensorflow.keras.utils.to_categorical(y_test, num_classes)

model = Sequential([
    Flatten(input_shape=(28,28)),
    Dense(32,input_dim=784),
    Activation("sigmoid"),
    Dense(10),
    Activation("softmax")
])

print(model.summary())
plot_model(model,to_file='shared_input_layer.png')
opt = keras.optimizers.RMSprop(learning_rate=0.0001,decay = 1e-6)
model.compile(loss='categorical_crossentropy',optimizer=opt,metrics=['accuracy'])
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs,validation_data=(x_test,y_test),shuffle=True)
scores = model.evaluate(x_test,y_test,verbose=1)
print("Test loss:",scores[0])
print("Test accuracy:",scores[1])

